package com.lovegu.collection.set;

import org.junit.Before;
import org.junit.Test;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author 老顾
 * @title: SetTest
 * @projectName java-restudy
 * @email: 1437594522@qq.com
 * @date 2022/9/24 10:45
 */
public class SetTest {
    public Set<String> names;
    @Before
    public void add() {
        names = new HashSet<>();
        names.add("lucy");
        names.add("tom");
        names.add("jerry");
    }
    @Test
    public void testIterator(){
        Iterator<String> iterator = names.iterator();
        // 每次都判断一下是不是有下一个，有的话，继续遍历
        while (iterator.hasNext()){
            // 获取下一个
            String name = iterator.next();
            System.out.println(name);
        }
    }
}
